﻿using System;
using System.Diagnostics;

namespace Common.TextMatch
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class PhoneticConverter : StringConverterBase
    {

        /// <summary>
        /// 
        /// </summary>
        public const int DefaultResultLength = 4;		//Provide 4 char encodings by default!

        private int resultLength;						//Allow default to be overriden

        /// We can't construct PhoneticConverters
        protected PhoneticConverter() : this(DefaultResultLength) { }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="resultLength"></param>
        protected PhoneticConverter(int resultLength)
        {
            //Ensure the value parameter is valid
            Debug.Assert(resultLength >= 0, "Unexpected null value.", "The PhoneticConverter.ctor(Int32) method requires a number equal or greater than zero.");

            this.ResultLength = resultLength;
        }

        //Allow the result length to be modified as required...
        /// <summary>
        /// 
        /// </summary>
        public int ResultLength
        {
            get { return this.resultLength; }
            set { this.resultLength = (value > 0) ? value : Int32.MaxValue; }
        }

        //Encodes a value using the algorithm.
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override abstract string Convert(string value);
    }
}
